import { HttpException, HttpStatus, ValidationError, ValidationPipe } from '@nestjs/common';

// 用于处理异常数据抛出的结果
export class Validate extends ValidationPipe {
    protected flattenValidationErrors(validationErrors: ValidationError[]): string[]{
        
        const message = {}
        validationErrors.forEach(error=>{
            message[error.property] = Object.values(error.constraints)[0]
            
        })
       
        throw new HttpException({
            code :422,
            message
        },
        HttpStatus.UNPROCESSABLE_ENTITY
    )

    }
}